import Vue from 'vue'
import vuex from 'vuex'
Vue.use(vuex);

export default new vuex.Store({
  state: {
    show: false,
    token: '',
    type: "portrait",
    user: {

    }
  },
  getters: {
    getUser(state) {
      console.log(state)
      if (state.user.mobile) {
        return state.user.mobile
      } else {
        return window.localStorage.getItem("current_user")
      }
    }
  },
  mutations: {
    setUser(state, user) {
      state.user = user
      window.localStorage.setItem('current_user',user.mobile)
    },
    setToken(state, token) {
      state.token = token
    },
    outUser(state) {
      state.user.name = ''
      window.localStorage.removeItem('current_user')
    },
    setType (state , type) {
      state.type = type
    }
  }
})
